package com.zhong.gang.applib.base.fm;

import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.DrawableRes;
import androidx.annotation.LayoutRes;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.zhong.gang.applib.R;

public abstract class FmBaseRefreshHeadAndFoot<T extends ViewDataBinding,M extends BaseQuickAdapter,H extends ViewDataBinding,F extends ViewDataBinding>
        extends FmBaseRefresh<T,M> {
    public H headbing;
    public F footbing;

    public void initrefrsh(SmartRefreshLayout swipeRefreshLayout, M adapter, RecyclerView recyclerView){
       initrefrsh(swipeRefreshLayout,adapter,recyclerView, R.mipmap.icon_not_data,"暂无数据~~");
    }

    public void initrefrsh(SmartRefreshLayout swipeRefreshLayout, M adapter, RecyclerView recyclerView, boolean isFill){
        initrefrsh(swipeRefreshLayout,adapter,recyclerView, R.mipmap.icon_not_data,"暂无数据~~",isFill);
    }


    public void initrefrsh(SmartRefreshLayout swipeRefreshLayout, M adapter, RecyclerView recyclerView
            , @DrawableRes int drawableRes, String str){
        initrefrsh(swipeRefreshLayout,adapter,recyclerView,drawableRes,str,true);
    }

    public void initrefrsh(SmartRefreshLayout swipeRefreshLayout, M adapter, RecyclerView recyclerView
            , @DrawableRes int drawableRes, String str, boolean isFill){
        super.initrefrsh(swipeRefreshLayout,adapter,recyclerView,drawableRes,str,isFill);
        if (adapter != null) {
            int headRes = addHeadView();
            if (headRes > 0) {
                View headView = LayoutInflater.from(getContext()).inflate(headRes, null);
                try {
                    headbing = DataBindingUtil.bind(headView);
                }catch (Exception e){}
                adapter.addHeaderView(headView);
            }
            int footRes = addFootView();
            if (footRes > 0) {
                View FootView = LayoutInflater.from(getContext()).inflate(footRes, null);
                try {
                    footbing = DataBindingUtil.bind(FootView);
                }catch (Exception e){}
                adapter.addFooterView(FootView);
            }
        }
    }

    @LayoutRes
    public abstract int addHeadView();
    @LayoutRes
    public abstract int addFootView();

}
